/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.Arrays;
import java.util.Random;

/**
 * <p>Project: jse2303 - Ex1
 * <p>Powered by webrx On 2023-07-19 09:30:43
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex1 {
    public static void main(String[] args) {
        //java写出随机0-9组成一个8位不重复数字的字符串，产生4个这样的字符串，也是互相不重复的
        String[] ss = new String[4];
        ok:
        for (int i = 0; i < 4; i++) {
            String s = getStr();
            for (String str : ss) {
                if (str != null && str.equals(s)) {
                    --i;
                    continue ok;
                }
            }
            ss[i] = s;
        }
        System.out.println(Arrays.toString(ss));
    }

    static String getStr() {
        Random rand = new Random();
        Integer[] ns = new Integer[10];
        for (int i = 0; i < 10; i++) ns[i] = i;
        //System.out.println(Arrays.toString(ns));
        Arrays.sort(ns, (a, b) -> Math.random() > .5 ? 1 : -1);
        //System.out.println(Arrays.toString(ns));
        StringBuilder sbu = new StringBuilder();
        for (int i = 0; i < 8; i++) {
            sbu.append(ns[i]);
        }
        return sbu.toString();
    }
}
